package 笔试.浪潮笔试.第一题石头;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int num=1,max=1;
        int tree=in.nextInt();
        int[] arr1=new int[tree];
        int[] arr2=new int[tree];
        for(int i=0;i<tree;i++)
        {
            arr1[i]=in.nextInt();
        }
        for(int i=0;i<tree;i++){
            arr2[i]=arr1[i];
            for(int j=i+1;j<tree;j++){
                arr2[j]=arr1[j];
                if(arr2[i]+1==arr2[j]){
                    num+=1;
                    arr2[i]=arr2[j];
                }
            }
            if(num>max){
                max=num;
            }
            num=1;
        }
        System.out.println(tree-max);
    }
}